#include <iostream>
#include <cstring>
using namespace std;
string maxs="";
string cut(string s,int l,int r)//截取字符串
{
	int i;
	string temp="";
	for (i = l; i <= r; i++)
	{
		temp += s[i];
	}
	return temp;
}

int bf(string a,string b)//a主串，b为模式串,判断是否匹配
{
	int la, lb, i, j, start;
	la = a.length();
	lb = b.length();
	i = j = start = 0;
	while(i<la&&j<lb)
	{
		if(a[i]==b[j])
		{
			i++;
			j++;
		}
		else
		{
			start++;
			i = start;
			j = 0;//模式串从头开始匹配
		}
	}
	if(j==lb)
		return 1;
	else
		return 0;
}

void maxstring(string a,string b)//a短,b长
{
	string s;
	int i, j, la;
	la = a.length();
	for (i = 0; i < la; i++)
	{
		for (j = i; j < la; j++)
		{
			s = cut(a, i, j);
			if(bf(b,s)!=0)
			{
				if(s.length()>maxs.length())//替换最长子串
				{
					maxs = s;
				}
			}
		}
	}
	//cout << maxs;
	printf("%s", maxs.c_str());
}
int main()
{
    char a[51],b[51];
	scanf("%s %s", a, b);
	//gets(a);
	//gets(b);
	if(strlen(a)<strlen(b))
		maxstring(a, b);
	else
		maxstring(b, a);
	return 0;
}
